import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:taonile/pages/asset_general_detail.dart';
import 'package:taonile/pages/asset_gold_detail.dart';
import 'package:taonile/pages/asset_packge.dart';
import 'package:taonile/pages/home_page.dart';
import 'package:taonile/pages/login_page.dart';
import 'package:taonile/pages/mall_home.dart';
import 'package:taonile/pages/mine_about.dart';
import 'package:taonile/pages/mine_account_safety.dart';
import 'package:taonile/pages/mine_address_choose.dart';
import 'package:taonile/pages/mine_address_edite.dart';
import 'package:taonile/pages/mine_address_manager.dart';
import 'package:taonile/pages/mine_announcement.dart';
import 'package:taonile/pages/mine_asset_exchange.dart';
import 'package:taonile/pages/mine_bankcard_add.dart';
import 'package:taonile/pages/mine_bankcard_manager.dart';
import 'package:taonile/pages/mine_change_mobile.dart';
import 'package:taonile/pages/mine_change_nickname.dart';
import 'package:taonile/pages/mine_change_password.dart';
import 'package:taonile/pages/mine_collect_page.dart';
import 'package:taonile/pages/mine_find_password.dart';
import 'package:taonile/pages/mine_getcash.dart';
import 'package:taonile/pages/mine_getcash_record.dart';
import 'package:taonile/pages/mine_info.dart';
import 'package:taonile/pages/mine_setting.dart';
import 'package:taonile/pages/mine_share_card.dart';
import 'package:taonile/pages/mine_stock.dart';
import 'package:taonile/pages/mine_stock_exchange.dart';
import 'package:taonile/pages/mine_team.dart';
import 'package:taonile/pages/my_store_tojoin.dart';
import 'package:taonile/pages/my_store_tojoin_audit.dart';
import 'package:taonile/pages/my_store_tojoin_before.dart';
import 'package:taonile/pages/my_store_tojoin_mall.dart';
import 'package:taonile/pages/my_store_tojoin_store.dart';
import 'package:taonile/pages/order_apply_refund.dart';
import 'package:taonile/pages/order_cashier.dart';
import 'package:taonile/pages/order_confirm_page.dart';
import 'package:taonile/pages/order_detail_page.dart';
import 'package:taonile/pages/order_index.dart';
import 'package:taonile/pages/order_publish_comment.dart';
import 'package:taonile/pages/order_refund_choose.dart';
import 'package:taonile/pages/order_refund_list.dart';
import 'package:taonile/pages/product_classify.dart';
import 'package:taonile/pages/product_detail_page.dart';
import 'package:taonile/pages/product_list.dart';
import 'package:taonile/pages/product_special_area.dart';
import 'package:taonile/pages/refund_order_detail.dart';
import 'package:taonile/pages/register_page.dart';
import 'package:taonile/pages/search_index.dart';
import 'package:taonile/pages/shopping_car.dart';
import 'package:taonile/pages/store_detail_page.dart';
import 'package:taonile/pages/store_hot.dart';
import 'package:taonile/pages/store_list.dart';
import 'package:taonile/pages/store_pay.dart';
import 'package:taonile/pages/store_pay_record.dart';
import 'package:taonile/pages/web_view.dart';

import '../pages/asset_yuanshigu_detail.dart';
import '../pages/mine_asset_transition.dart';
import '../pages/order_query_express.dart';
import '../pages/photo_view.dart';

///
/// fluro路由的跳转动作封装
///

// 跳转首页
Handler homePageHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const HomePage();
});

// 跳转登录页
Handler loginPageHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const LoginPage();
});

// 跳转注册页
Handler registerPageHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const RegisterPage();
});

// 跳转通用的资产详情
Handler assetGeneralDtailPageHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? pageTitle = parameters['pageTitle']?.first;
  pageTitle ??= "";
  String? assetType = parameters['assetType']?.first;
  assetType ??= "";
  String? amount = parameters['amount']?.first;
  amount ??= "";

  return AssetGeneralDetail(pageTitle: pageTitle, assetType: assetType, amount: amount);
});

// 跳转商品详情页面
Handler productDtailPageHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? productId = parameters['productId']?.first;
  productId ??= "";
  return ProductDetailPage(
    productId: productId,
  );
});

// 跳转公告页面
Handler announcementPageHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const Announcement();
});

// 跳转订单确认页面
Handler orderConfirmPageHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? buyNum = parameters['buyNum']?.first;
  buyNum ??= "";
  String? tag = parameters['tag']?.first;
  tag ??= "1";
  String? productName = parameters['productName']?.first;
  productName ??= "";
  String? storeName = parameters['storeName']?.first;
  storeName ??= "";
  String? storeLogo = parameters['storeLogo']?.first;
  storeLogo ??= "";
  String? storeId = parameters['storeId']?.first;
  storeId ??= "";
  String? isCar = parameters['isCar']?.first;
  isCar ??= "0";
  String? amount = parameters['amount']?.first;
  amount ??= "0";
  String? expressMoney = parameters['expressMoney']?.first;
  expressMoney ??= "0";

  return OrderConfirmPage(
      buyNum: buyNum,
      productName: productName,
      storeName: storeName,
      storeLogo: storeLogo,
      storeId: storeId,
      isCar: isCar,
      amount: amount,
      tag: tag,
      expressMoney: expressMoney);
});

// 我的订单主页
Handler orderIndexPageHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? currentIndex = parameters['currentIndex']?.first;
  currentIndex ??= '0';
  return OrderIndexPage(currentIndex: int.parse(currentIndex));
});

// 跳转订单详情页面
Handler orderDetailHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? orderNo = parameters['orderNo']?.first;
  orderNo ??= "";
  return OrderDetailPage(orderNo: orderNo);
});

// 商品分类页面
Handler productClassifyHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const ProductClassifyPage();
});

// 跳转商品分类/搜索列表
Handler productListHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? cateId = parameters['cateId']?.first;
  cateId ??= "";
  String? keyword = parameters['keyword']?.first;
  keyword ??= "";
  String? sourceId = parameters['sourceId']?.first;
  sourceId ??= "";
  return ProductListPage(cateId: cateId, keyword: keyword, sourceId: sourceId);
});

// 跳转商品专区
Handler productSpecialAreaHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? pageTitle = parameters['pageTitle']?.first;
  pageTitle ??= "";
  String? areaId = parameters['areaId']?.first;
  areaId ??= "";
  return ProductSpecialAreaPage(
    pageTitle: pageTitle,
    areaId: areaId,
  );
});

// 跳转收银台页面
Handler cashierPageHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? amount = parameters['amount']?.first;
  amount ??= "";
  String? orderNo = parameters['orderNo']?.first;
  orderNo ??= "";
  String? skuId = parameters['skuId']?.first;
  skuId ??= "";
  String? payApiType = parameters['payApiType']?.first;
  payApiType ??= "1";

  return OrderCashier(amount: amount, orderNo: orderNo, skuId: skuId, payApiType: payApiType);
});

// 跳转我的团队
Handler mineTeamPageHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? userId = parameters['userId']?.first;
  userId ??= "";
  String? isMe = parameters['isMe']?.first;
  isMe ??= '0';
  return MineTeam(userId: userId, isMe: int.parse(isMe));
});

// 跳转资产金券
Handler assetGoldPageHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const AssetGoldDetail();
});

// 跳转总资产
Handler assetPackgePageHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const AssetPackgeDetail();
});

// 跳转购物车
Handler shoppingCarPageHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const ShoppingCarPage();
});

// 跳转修改昵称
Handler mineChangeNicknameHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const MineChangeNickname();
});

// 跳转修改密码
Handler mineChangePasswordHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? pageTitle = parameters['pageTitle']?.first;
  pageTitle ??= "";
  return MineChangePassword(pageTitle: pageTitle);
});

// 跳转账户安全
Handler mineAccountSafetyHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const MineAccountSafety();
});

// 跳转资产互转
Handler mineAssetTransitionHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? amount = parameters['amount']?.first;
  amount ??= "";
  return MineAssetTransition(amount: amount);
});

// 跳转资产兑换
Handler mineAssetExchangeHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? amount = parameters['amount']?.first;
  amount ??= "";
  return MineAssetExchange(amount: amount);
});

// 跳转店铺首页
Handler mallHomeHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? storeId = parameters['storeId']?.first;
  storeId ??= "";
  String? currentIndex = parameters['currentIndex']?.first;
  currentIndex ??= "0";
  return MallHomePage(storeId: storeId, currentIndex: currentIndex);
});

// 跳转搜索页面
Handler searchIndexHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? source = parameters['source']?.first;
  source ??= "";
  return SearchIndexPage(source: source);
});

// 跳转我的名片
Handler mineShareCardHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const MineShareCard();
});

// 跳转修改手机
Handler mineChangeMobileHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return MineChangeMobile();
});

// 跳转找回密码
Handler mineFindPasswordHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return MineFindPassword();
});

// 跳转管理收货地址
Handler mineAddressManagerHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const MineAddressManager();
});

// 跳转添加/修改收货地址
Handler mineAddressEditHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? receiptId = parameters['receiptId']?.first;
  receiptId ??= "";
  return MineAddressEdit(receiptId: receiptId);
});

// 跳转添加/修改收货地址
Handler mineAddressChooseHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const MineAddressChoose();
});

// 跳转我的收藏
Handler mineCollectHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const MineCollectPage();
});

// 跳转到个人中心
Handler mineInfoHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const MineInfo();
});

// 跳转到设置
Handler mineSettingHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const MineSetting();
});

// 跳转到关于我们
Handler mineAboutHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const MineAbout();
});

// 跳转webView
Handler webViewHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? pageTitle = parameters['pageTitle']?.first;
  pageTitle ??= "";
  String? webUrl = parameters['webUrl']?.first;
  webUrl ??= "";
  return WebViewPage(pageTitle: pageTitle, webUrl: webUrl);
});

// 跳转发表评价
Handler publishCommentHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? sourceType = parameters['sourceType']?.first;
  sourceType ??= "";
  return OrderPublishComment(sourceType: sourceType);
});

// 跳转银行卡管理
Handler mineBankcardManagerHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const BankcardManager();
});

// 跳转添加银行卡
Handler mineBankcardAddHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? accountId = parameters['accountId']?.first;
  accountId ??= "";
  return MineBankcardAdd(accountId: accountId);
});

// 跳转提现
Handler mineGetCashHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? amount = parameters['amount']?.first;
  amount ??= '0';
  return MineGetCash(amount: amount);
});

// 跳转提现记录
Handler mineGetCashRecordHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return MineGetcashRecord();
});

// 跳转商圈实体店详情
Handler storeDetailHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? storeId = parameters['storeId']?.first;
  storeId ??= "";
  return StoreDetailPage(storeId: storeId);
});

// 跳转实体店列表
Handler storeListHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  // String? storeId = parameters['storeId']?.first;
  // storeId ??= "";
  return const StoreList();
});

// 跳转实体店热门推荐
Handler storeHotHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  // String? storeId = parameters['storeId']?.first;
  // storeId ??= "";
  return const StoreHot();
});

// 跳转实体店付款
Handler storePayHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  // String? storeId = parameters['storeId']?.first;
  // storeId ??= "";
  return const StorePay();
});

// 跳转实体店消费记录
Handler storePayRecordHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const StorePayRecord();
});

// 跳转到入驻的信息页面
Handler myStoreToJoinBeforeHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const MyStoreToJoinBefore();
});

// 跳转到入驻的选择页面
Handler myStoreToJoinHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const MyStoreToJoin();
});

// 跳转到入驻线上商城
Handler myStoreToJoinMallHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? id = parameters['id']?.first;
  id ??= "";
  return MyStoreToJoinMall(id: id);
});

// 跳转到入驻附近商圈
Handler myStoreToJoinStoreHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? id = parameters['id']?.first;
  id ??= "";
  return MyStoreToJoinStore(id: id);
});

// 跳转到入驻审核
Handler myStoreToJoinAuditHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const MyStoreToJoinAudit();
});

// 跳转到退款单列表
Handler orderRefundListHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const OrderRefundListPage();
});

// 跳转到退换货服务选择
Handler orderRefundChoosePageHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? orderNo = parameters['orderNo']?.first;
  orderNo ??= "";
  String? goodsId = parameters['goodsId']?.first;
  goodsId ??= "";
  String? img = parameters['img']?.first;
  img ??= "";
  String? name = parameters['name']?.first;
  name ??= "";
  String? spec = parameters['spec']?.first;
  spec ??= "";
  String? price = parameters['price']?.first;
  price ??= "";
  String? num = parameters['num']?.first;
  num ??= "";

  return OrderRefundChoosePage(
      orderNo: orderNo, goodsId: goodsId, img: img, name: name, spec: spec, price: price, num: num);
});

// 跳转到申请退款或退货退款
Handler orderApplyRefundHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? type = parameters['type']?.first;
  type ??= "1";
  String? orderNo = parameters['orderNo']?.first;
  orderNo ??= "";
  String? goodsId = parameters['goodsId']?.first;
  goodsId ??= "";
  String? img = parameters['img']?.first;
  img ??= "";
  String? name = parameters['name']?.first;
  name ??= "";
  String? spec = parameters['spec']?.first;
  spec ??= "";
  String? price = parameters['price']?.first;
  price ??= "";
  String? num = parameters['num']?.first;
  num ??= "";

  return OrderApplyRefund(
      type: type,
      orderNo: orderNo,
      goodsId: goodsId,
      img: img,
      name: name,
      spec: spec,
      price: price,
      num: num);
});

// 跳转退款单详情页面
Handler refundOrderDetailHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? orderNo = parameters['orderNo']?.first;
  orderNo ??= "";
  String? isShowExpress = parameters['isShowExpress']?.first;
  isShowExpress ??= "0";

  return RefundOrderDetail(orderNo: orderNo, isShowExpress: isShowExpress);
});

// 跳转物流进度查询
Handler orderQueryExpressHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? orderNo = parameters['orderNo']?.first;
  orderNo ??= "";
  return OrderQueryExpress(orderNo: orderNo);
});

// 跳转我的股票
Handler mineStockHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return const MineStock();
});

// 跳转股票兑换
Handler mineStockExchangeHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  return MineStockExchange();
});

// 跳转通用的资产详情
Handler assetYuanshiguDetailHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? pageTitle = parameters['pageTitle']?.first;
  pageTitle ??= "";
  String? assetType = parameters['assetType']?.first;
  assetType ??= "";
  String? amount = parameters['amount']?.first;
  amount ??= "";
  String? amount2 = parameters['amount2']?.first;
  amount2 ??= "";
  return AssetYuanshiguDetail(
      pageTitle: pageTitle, assetType: assetType, amount: amount, amount2: amount2);
});

// 跳转到大图浏览
Handler photoPreviewHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  String? defaultImage = parameters['defaultImage']?.first;
  defaultImage ??= '0';
  return PhotoPreview(
    defaultImage: int.parse(defaultImage),
  );
});

//找不到路由
Handler notFoundHandler =
    Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> parameters) {
  print('页面找不到404');
  return null;
});
